home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / NetWarmer / source / Scrolling.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-11  |  2.8 KB  |  124 lines  |  [TEXT/KAHL]

  1. /* © 1988, Bowers Development Corp. */
  2. /* Scrolling.c */
  3.  
  4. #include "Globals.h"    
  5.  
  6. #include "Scrolling.h"
  7.  
  8.  
  9. /*----------*/
  10. void ResizeScrollBars    ()
  11. {
  12.     short            curTop;
  13.     short            curLeft;
  14.     Rect            portRect;
  15.     
  16.     portRect = curWindow->portRect;
  17.     if (cur->vScroll != nil) {
  18.         curTop = (**(cur->vScroll)).contrlRect.top;
  19.         HideControl (cur->vScroll);
  20.         MoveControl (cur->vScroll,
  21.                      (portRect.right + 1) - sBarWidth,
  22.                      curTop);
  23.         SizeControl (cur->vScroll,
  24.                      sBarWidth,
  25.                      ((portRect.bottom + 1) - sBarWidth) + 1 - curTop);
  26.         ShowControl (cur->vScroll);
  27.         ValidRect (&(**(cur->vScroll)).contrlRect);
  28.     }
  29.     
  30.     if (cur->hScroll != nil) {
  31.         curLeft = (**(cur->hScroll)).contrlRect.left;
  32.         HideControl (cur->hScroll);
  33.         MoveControl (cur->hScroll,
  34.                      curLeft,
  35.                      (portRect.bottom + 1) - sBarWidth);
  36.         SizeControl (cur->hScroll,
  37.                      ((portRect.right + 1) - sBarWidth) + 1 - curLeft,
  38.                      sBarWidth);
  39.         ShowControl (cur->hScroll);
  40.         ValidRect (&(**(cur->hScroll)).contrlRect);
  41.     }
  42. } /*ResizeScrollBars*/
  43.  
  44. /*----------*/
  45. void DoScrollPart    (whichScroll, partCode)
  46. ControlHandle    whichScroll;
  47. short            partCode;
  48. {
  49.     short            pageSize;
  50.     short            delta;
  51.     short            oldValue;
  52.  
  53.     pageSize = GetCRefCon (whichScroll);
  54.     switch (partCode) {
  55.     case inUpButton:
  56.             delta = -1;
  57.         break;
  58.     case inDownButton:
  59.             delta = 1;
  60.         break;
  61.     case inPageUp:
  62.             delta = -pageSize;
  63.         break;
  64.     case inPageDown:
  65.             delta = pageSize;
  66.         break;
  67.     default:
  68.             delta = 0;
  69.         break;
  70.     } /*switch*/
  71.     if (delta != 0) {
  72.         oldValue = GetCtlValue (whichScroll);
  73.         SetCtlValue (whichScroll, oldValue + delta);
  74.     }
  75. } /*DoScrollPart*/
  76.     
  77. /*----------*/
  78. pascal void ActionGlue (ControlHandle   whichScroll,
  79.                         short           partCode);
  80. pascal void ActionGlue (whichScroll, partCode)
  81. ControlHandle    whichScroll;
  82. short            partCode;
  83. {
  84.     short            oldValue;
  85.     short            newValue;
  86.     ProcPtr            actionProc;
  87.  
  88.     oldValue = GetCtlValue (whichScroll);
  89.     DoScrollPart (whichScroll, partCode);
  90.     newValue = GetCtlValue (whichScroll);
  91.     if (newValue != oldValue) {
  92.         actionProc = (**whichScroll).contrlAction;
  93.         CallPascal (newValue, oldValue, actionProc);
  94.     }
  95. } /*ActionGlue*/
  96.  
  97. /*----------*/
  98. void TrackScroll    (whichScroll, partCode, where, actionProc)
  99. ControlHandle    whichScroll;
  100. short            partCode;
  101. Point            where;
  102. ProcPtr            actionProc;
  103. {
  104.     short            oldValue;
  105.     short            newValue;
  106.  
  107.     if (partCode == inThumb) {
  108.         oldValue = GetCtlValue (whichScroll);
  109.         partCode = TrackControl (whichScroll, where, nil);
  110.         if (actionProc != nil) {
  111.             newValue = GetCtlValue (whichScroll);
  112.             CallPascal (newValue, oldValue, actionProc);
  113.         }
  114.     } else {
  115.         if (actionProc == nil) {
  116.             partCode = TrackControl (whichScroll, where, nil);
  117.             DoScrollPart (whichScroll, partCode);
  118.         } else {
  119.             (**whichScroll).contrlAction = actionProc;
  120.             partCode = TrackControl (whichScroll, where, (ProcPtr) &ActionGlue);
  121.         }
  122.     }
  123. } /*TrackScroll*/
  124.